home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / CALCULTR / MCALC / TESTCALC.PAS < prev    next >
Pascal/Delphi Source File  |  1996-07-24  |  2KB  |  61 lines

  1. (*
  2.  
  3. TRY LAUNCHING A CALC, EX: 2+2 AND WITHOUT REMOVING THE RESULT WINDOW (DON'T PRESS
  4. ok, LAUNCH ANOTHER CALCULATION...MULTITHREAD IS REALLY USEFUL! You'll never wait
  5. until a calculation is finished!
  6.  
  7. *)
  8.  
  9.  
  10. unit TestCalc;
  11.  
  12. interface
  13.  
  14. uses
  15.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  16.   StdCtrls, MCalc, TreeView;
  17.  
  18. type
  19.   {this is a class derived from the pure TCalcThread, so it's easy to get result
  20.    of the calculation }
  21.   Calculator=class(TCalcThread)
  22.      private
  23.         procedure UpdateResult; override;             {redefine the update res}
  24.      end;
  25.  
  26.   TForm1 = class(TForm)
  27.     Button1: TButton;
  28.     Edit1: TEdit;
  29.     procedure Button1Click(Sender: TObject);
  30.   private
  31.   public
  32.   end;
  33.  
  34. var
  35.   Form1: TForm1;
  36.  
  37. implementation
  38.  
  39. {$R *.DFM}
  40.  
  41. procedure Calculator.UpdateResult;
  42. begin
  43.    inherited;                     {call the previous version !!! you must do it}
  44.    MessageDlg('Result: '+CalcStrResult+Chr(10)+Chr(13)+'Error: '+RaisedError,mtInformation,[mbOk],0);
  45.    {show the result!}
  46.    end;
  47.  
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. var
  50.    Variables: PNode;
  51. begin
  52.    {create a variable tree, you may do this once for a global variable tree and each
  53.    time you launch another calc reuse it, so variables will be kept}
  54.    New(Variables,Create(NodeVariable,'Variable Tree (private):'));
  55.    {create the inherited calculator thread, UpdateResult will be called as
  56.    the calculation is finished}
  57.    Calculator.Create(Edit1.Text,Variables,Deg,0);
  58.    end;
  59.  
  60. end.
  61.